package com.example.demo.controller;

import com.example.demo.pojo.Result;
import com.example.demo.pojo.dto.ShoppingCartAddDTO;
import com.example.demo.pojo.entity.ShoppingCart;
import com.example.demo.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/polycystic/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @GetMapping("/list")
    public Result<List<ShoppingCart>> list(){
        List<ShoppingCart> list=shoppingCartService.list();
        return Result.success(list);
    }

    @GetMapping("/{id}")
    public Result select(@PathVariable Long id){
        shoppingCartService.select(id);
        return Result.success();
    }

    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartAddDTO shoppingCartAddDTO){
        shoppingCartService.add(shoppingCartAddDTO);
        return Result.success();
    }

    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartAddDTO shoppingCartAddDTO){
        shoppingCartService.sub(shoppingCartAddDTO);
        return Result.success();
    }

    @DeleteMapping("/clean")
    public Result cleanShoppingCart(){
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }
}
